﻿$(function () {
    layui.use('form', function () {
        var form = layui.form,
            layer = layui.layer,
            $ = layui.jquery;
        //监听启用开关
        form.on("switch(switchEnable)", function (data) {
            var _this = $(this);
            if (this.checked) {
                _this.val(1);
            } else {
                _this.val(0);
            }
        });

        //表单提交
        form.on('submit(submit)', function (data) {
            $.ajax({
                url: "/Module/AddModule",
                method: 'post',
                data: data.field,
                dataType: 'JSON',
                success: function (res) {
                    if (res.success) {
                        //验证码效验成功之后提交到后台
                        layer.msg(res.msg, {
                            title: '提示框',
                            icon: 1,
                            time: 3000,
                            end: function () {
                                window.location.href = "/Module/Index";
                            }
                        });
                    }
                    else {
                        layer.alert(res.msg);
                        return false;
                    }
                },
                error: function (data) {

                }
            })
        })
    })
})